<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>阶段1： </label>
                                <input type="text" class="time-input" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li class="select-time">
                                <label>阶段2： </label>
                                <input type="text" class="time-input" placeholder="开始时间" name="params[beginTime2]"/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="params[endTime2]"/>
                            </li><li class="select-time">
                                <label>阶段3： </label>
                                <input type="text" class="time-input" placeholder="开始时间" name="params[beginTime3]"/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="params[endTime3]"/>
                            </li><li class="select-time">
                                <label>阶段4： </label>
                                <input type="text" class="time-input" placeholder="开始时间" name="params[beginTime4]"/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="params[endTime4]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;统计</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 " style="height: 400px">
                <div id="mychart" style="width: 100%;height: 100%;" ></div>
            </div>
            <div class="col-sm-12 " style="height: 400px">
                <div id="mychart2" style="width: 100%;height: 100%;" ></div>
            </div>
        </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var option = {
            title: {
                text: '营业额阶段对比',
                left: 'center'
            },
            color: ['#3398DB'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '营业额(元)',
                    type: 'bar',
                    barWidth: '60%',
                    data: [10, 52, 200, 334, 390, 330, 220]
                }
            ]
        };

        var option2 = {
            title: {
                text: '营业额阶段占比',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
            },
            series: [
                {
                    name: '营业额(元)',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: [
                        {value: 335, name: '直接访问'},
                        {value: 310, name: '邮件营销'},
                        {value: 234, name: '联盟广告'},
                        {value: 135, name: '视频广告'},
                        {value: 1548, name: '搜索引擎'}
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };


        function query() {
            $.ajax({
                url:ctx+"user/userOrder/statistics2",
                data:$("#user-form").serialize(),
                type:"post",
                dataType:"json",
                success:function (data) {
                    var xAxisData = [];
                    for(var i=0;i<data.length;i++){
                        xAxisData.push(data[i].name);
                    }
                    option.xAxis[0].data = xAxisData;
                    option.series[0].data = data;
                    var mychart = echarts.init($("#mychart")[0]);
                    mychart.setOption(option,true);

                    option2.legend.data = xAxisData;
                    option2.series[0].data = data;
                    var mychart2 = echarts.init($("#mychart2")[0]);
                    mychart2.setOption(option2,true)
                }
            })
        }
        $(function () {
            query();
        })
    </script>
</body>
</html>